import _mixins from './_mixins';
import _action from './_action';
import _data from './_data';

export default {
	/**通用数据接口
	 * @param {Object} param 接口参数
	 * 可返回success、fail、complete回调、$emit、函数回调、promise
	 */
	getData(param,fn){
		console.log("第一步getData的报文",param,fn);
		console.log(param);
		return new Promise((resolve,reject) => {
			_mixins.methods.$custom_httpSend({
				data: param,
				success(data) {
					if(data.count=='0') {//返回值为空，则为空数组
						data.data = []
					}
					if(param.name) {
						uni.$emit(param.name,data.data)
					} else if(param.success) {
						param.success(data.data)
					} else if(fn) {
						fn(data.data)
					} else {
						resolve(data.data)
					}
				},
				fail(res) {
					if(param.fail) {
						param.fail(res)
					}
					// reject(res)
				},
				complete() {
					if(param.complete) {
						param.complete()
					}
				}
			});
		})
	},
	
	
	getDataJava(param,fn){
		return new Promise((resolve,reject) => {
			_mixins.methods.$httpJavaSend({
				data: param,
				success(data) {
					if(data.count=='0') {//返回值为空，则为空数组
						data.data = []
					}
					if(param.name) {
						uni.$emit(param.name,data.data)
					} else if(param.success) {
						param.success(data.data)
					} else if(fn) {
						fn(data.data)
					} else {
						resolve(data.data)
					}
				},
				fail(res) {
					if(param.fail) {
						param.fail(res)
					}
					// reject(res)
				},
				complete() {
					if(param.complete) {
						param.complete()
					}
				}
			});
		})
	},
	
	
	
	/**获取点位数据
	 * @param {Object} param 参数
	 */
	getCnlDataList(param){
		_mixins.methods.$custom_httpSend({
			data: param,
			success(data) {
				uni.$emit(param.apiparam[0].cnlcode,data.data)
			}
		});
	},
	/** 
	 * 获得会话列表数据  
	*/
	custom_getChatList(param){
		_mixins.methods.$httpSend({
			path: '/im/work/workChatList',
			data: param,
			success(data) {
				if(param.name) {
					uni.$emit(param.name,data);
				} else if(param.success) {
					param.success(data);
				}
				_data.localData('custom_chat_list',data);
			}
		});
	},
	/**
	 * 获取事务会话数据
	 */
	getWorkChatList() {
		let index = _data.localData('work_index')
		index = index ? index : 0;
		switch(index) {
			case 1:
				this.custom_getChatList({
					name: 'db-list',
					work_type: '1'
				})
				break;
			case 2:
				this.custom_getChatList({
					name: 'wc-list',
					work_type: '2'
				})
				break;
			case 3:
				this.custom_getChatList({
					name: 'gq-list',
					work_type: '3'
				})
				break;
		}
	},
}